package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.annotation.DataScope;
import com.smart.common.core.domain.R;
import com.smart.common.core.page.PageQuery;
import com.smart.system.domain.vo.EmployeeSetVo;
import com.smart.system.domain.vo.EmployeeTrajectoryVo;
import com.smart.system.domain.vo.NowEmployeeTrajectoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.Employee;
import com.smart.system.service.IEmployeeService;
import com.smart.common.core.page.TableDataInfo;

/**
 * 员工Controller
 * 
 * @author smart
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/employee")
@Api(tags = "员工")
public class EmployeeController extends BaseController
{
    @Autowired
    private IEmployeeService employeeService;

    /**
     * 查询员工列表
     */
    @ApiOperation(value = "查询员工列表")
    //@PreAuthorize("@ss.hasPermi('system:employee:list')")
    @DataScope(deptAlias = "d",userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo<Employee> list(Employee employee)
    {
        IPage iPage = startIPage();
        IPage<Employee> list = employeeService.selectEmployeePage(employee,iPage);
        return getDataTable(list);
    }

    /**
     * 获取员工详细信息
     */
    @ApiOperation(value = "获取员工详细信息")
    //@PreAuthorize("@ss.hasPermi('system:employee:query')")
    @DataScope(deptAlias = "d")
    @GetMapping(value = "/{id}")
    public R<Employee> getInfo(@PathVariable("id") String id)
    {
        return R.ok(employeeService.selectEmployeeById(id));
    }

    /**
     * 新增员工
     */
    @ApiOperation(value = "新增员工")
    //@PreAuthorize("@ss.hasPermi('system:employee:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Integer> add(@RequestBody Employee employee)
    {
        return R.ok(employeeService.insertEmployee(employee));
    }

    /**
     * 修改员工
     */
    @ApiOperation(value = "修改员工")
    //@PreAuthorize("@ss.hasPermi('system:employee:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Integer> edit(@RequestBody Employee employee)
    {
        return R.ok(employeeService.updateEmployee(employee));
    }

    /**
     * 删除员工
     */
    @ApiOperation(value = "删除员工")
    //@PreAuthorize("@ss.hasPermi('system:employee:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable String[] ids)
    {
        return R.ok(employeeService.deleteEmployeeByIds(ids));
    }

    /**
     * 冻结员工
     */
    @ApiOperation(value = "冻结员工/解冻员工")
    //@PreAuthorize("@ss.hasPermi('system:employee:remove')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @DeleteMapping("/frost")
    public R<Boolean> frost(String id)
    {
        return R.ok(employeeService.frostEmployee(id));
    }

    /**
     * 查询所以员工时间间段内轨迹
     */
    @ApiOperation(value = "查询员工时间间段内轨迹")
    //@PreAuthorize("@ss.hasPermi('system:employee:list')")
    @GetMapping("/listTrajectory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "查询关键字", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, dataType = "String")
    })
    public R<IPage<EmployeeTrajectoryVo>> listTrajectory(String content, String startTime, String endTime, PageQuery pageQuery)
    {
        return R.ok(employeeService.listEmployeeTrajectory(content,startTime, endTime,pageQuery.toPage()));
    }

    @ApiOperation(value = "查询轨迹员工列表")
    //@PreAuthorize("@ss.hasPermi('system:employee:list')")
    @GetMapping("/listTrajectoryToEmployee")
    public R<List<NowEmployeeTrajectoryVo>> listTrajectoryToEmployee(Date startTime, Date endTime,Integer id){
        return R.ok(employeeService.listTrajectoryToEmployee(startTime,endTime,id));
    }

    /**
     * 设置手环
     */
    @ApiOperation(value = "设置手环")
    //@PreAuthorize("@ss.hasPermi('system:employee:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping("/setWatches")
    public R<Boolean> setBand(@RequestBody EmployeeSetVo employeeSetVo)
    {
        return R.ok(employeeService.setWatches(employeeSetVo));
    }
}
